package LocalServerProtocols;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;

public class GetLastCommercialSent extends localServerProtocol
{

	public GetLastCommercialSent()
	{
		super();
		this._serverResponse = null;
		this._firstDesieredServerRespose = null;
		this._secondDesieredServerRespose = null;
		this._protocolAction = "NUM_OF_MSG_SENT";
	}

	@Override
	public Object exec(ObjectOutputStream oos, PrintWriter out,
			BufferedReader in, ObjectInputStream ois, String action)
	{
		//write command to Server
		out.flush();
		out.println(action);
		System.out.println(this.getClass().getSimpleName() + ": I sent to Server "+action);
		
		//Try to read Date object from server
		

		//Sending Details to server
		try
		{
			System.out.println(this.getClass().getSimpleName() + ": Try to read String object that was sent to me");
			String resultStr = in.readLine();
			int resultInt = Integer.parseInt(resultStr);
			return Integer.valueOf( resultInt );
		}
		catch (IOException e)
		{
//			e.printStackTrace();
			System.err.println(e.getMessage());
			System.err.println(this.getClass().getSimpleName() + ": Couldn't read String object to Server");
		}
		catch (Exception e)
		{
//			e.printStackTrace();
			System.err.println(e.getMessage());
			System.err.println(this.getClass().getSimpleName() + ": Couldn't read String object to Server");
		}
		return Integer.valueOf( Integer.MAX_VALUE ); 
	}

}
